import { createBrowserRouter, Navigate } from 'react-router-dom';
import { ProtectedRoute } from '@/components/ProtectedRoute';
import { ErrorBoundary } from '@/components/ErrorBoundary';
import { HomePage } from '@/pages/HomePage';
import { LoginPage } from '@/pages/LoginPage';
import { RegisterPage } from '@/pages/RegisterPage';
import { AboutPage } from '@/pages/AboutPage';

export const router = createBrowserRouter([
  {
    path: '/',
    element: (
      <ErrorBoundary>
        <ProtectedRoute requireAuth={true}>
          <HomePage />
        </ProtectedRoute>
      </ErrorBoundary>
    ),
    errorElement: <ErrorBoundary><div>页面出错了</div></ErrorBoundary>,
  },
  {
    path: '/login',
    element: (
      <ErrorBoundary>
        <ProtectedRoute requireAuth={false}>
          <LoginPage />
        </ProtectedRoute>
      </ErrorBoundary>
    ),
    errorElement: <ErrorBoundary><div>页面出错了</div></ErrorBoundary>,
  },
  {
    path: '/register',
    element: (
      <ErrorBoundary>
        <ProtectedRoute requireAuth={false}>
          <RegisterPage />
        </ProtectedRoute>
      </ErrorBoundary>
    ),
    errorElement: <ErrorBoundary><div>页面出错了</div></ErrorBoundary>,
  },
  {
    path: '/about',
    element: (
      <ErrorBoundary>
        <ProtectedRoute requireAuth={true}>
          <AboutPage />
        </ProtectedRoute>
      </ErrorBoundary>
    ),
    errorElement: <ErrorBoundary><div>页面出错了</div></ErrorBoundary>,
  },
  {
    path: '*',
    element: <Navigate to="/" replace />,
  },
], {
  future: {
    v7_startTransition: true,
  },
});
